import { message } from 'antd';
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';

const AuthRoute = ({ children, auth }: any) => {
  const navigate = useNavigate();
  const token = localStorage.getItem('token') || '';

  useEffect(() => {
    if (token == '' && auth) {
      message.error('token 过期，请重新登录!');
      navigate('/login');
    }
    console.log(location);
  }, [token, location.pathname]);

  return children;
};

export default AuthRoute;
